<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	</head>
	<body>
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			
			<ul class="breadcrumb">
				<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
				<li>用户中心</li>
				<li class="active">菜单管理</li>
			</ul>
			
			
		</div>
		
		<div class="page-content">
			<div class="page-header">
				<h1>菜单管理
					<small>
					<i class="icon-double-angle-right"></i>
					查看
					</small>					
				</h1>			
			</div>
			<div class="row">
				<div class="col-xs-12">
				<table id="simple-table" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
					<thead>
						<tr>
							<th class='center' style="width:50px;">序号</th>
							<th colspan="2">名称</th>
						    <th >类型</th>
						    <th >路径</th>
						    <th >排序</th>
						    <th style="text-align: center;">操作</th>			
						</tr>								
					</thead>
					<tbody id="rolelist">
					
					<c:forEach var="res" items="${list}"  varStatus="status">
						<tr id="userinfo_row_${res.resourceId}">
							<td align="center">${status.index+1}</td>  
							<td colspan="2">${res.resName}&nbsp;</td>
							<td>
			        		<c:choose>
				            	<c:when test="${res.type ==1}">菜单</c:when>
				            	<c:otherwise>按钮</c:otherwise>
				            </c:choose>
			        		</td>
			        		<td>${res.resUrl}&nbsp;</td>
			        		<td title="${res.indexNum}">${res.indexNum}&nbsp;</td>
			        		<td>
			        			<div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
				        				<button title="编辑" class="btn btn-xs btn-info" onclick="location='${ctx}/sys/resource/toUpdate/${res.resourceId}'">
												<i class="icon-edit bigger-120"></i>
										</button>
						            <c:if test="${res.havechild !=1}">
						            	<button title="删除" class="btn btn-xs btn-danger" onclick="javascript:deleteRes(${res.resourceId});">
												<i class="icon-trash bigger-120"></i>
										</button>
						            </c:if>
						            <button title="添加" class="btn btn-xs btn-info" onclick="location='${ctx}/sys/resource/toAdd/${res.resourceId}'">
										<i class="icon-ok bigger-120"></i>
									</button>
			        			</div>
					            
							</td>
						</tr>
						
						<c:if test="${res.havechild ==1}">
				        <c:forEach var="res1" items="${res.list}"  varStatus="status1">
				        <tr id="userinfo_row_${res1.resourceId}">
				        	<td>&nbsp;</td>  
				        	<td>&nbsp;</td>
				        	<td >${res1.resName}&nbsp;</td>
				        	<td >
				        		<c:choose>
					            	<c:when test="${res1.type ==1}">菜单</c:when>
					            	<c:otherwise>按钮</c:otherwise>
					            </c:choose>
				        	</td>
				        	<td>${res1.resUrl}&nbsp;</td>
				        	<td>${res1.indexNum}&nbsp;</td>
				        	<td>
					            <button title="编辑" class="btn btn-xs btn-info" onclick="location='${ctx}/sys/resource/toUpdate/${res1.resourceId}'">
										<i class="icon-edit "></i>
								</button>
					            <button title="删除" class="btn btn-xs btn-danger" onclick="javascript:deleteRes(${res1.resourceId});">
										<i class="icon-trash "></i>
								</button>
							</td>
				        </tr>
				        </c:forEach>
				        </c:if>
					</c:forEach>
					
					</tbody>
					
				</table>
				</div>
				</div>
				<div>
					<a class="btn btn-sm btn-success" href="${ctx}/sys/resource/toAdd/-1">新增菜单</a>
				</div>
			</div>
			<script type="text/javascript">
			function deleteRes(resourceId){
				if(confirm("您确认删除该条记录吗?")){
					//resetRowById(userId);
					$.ajax({
						type : "DELETE",
						dataType: "json",
						async: false,
						url: '${ctx}/sys/resource/delete/'+resourceId,
						success: function (data) {
									if(data!=undefined&&data.status!=undefined&&data.status.trim()=="0"){
										$("#userinfo_row_"+resourceId).remove();
										alert("删除成功。");
									}else{
										alert("error:"+data.error);
									}
								 },
						error: function(data) {
									alert("删除失败。");
								}
					});
					return false;
				}
			}
			
			
			</script>
	</body>
	
	
</html>